class MainScene extends eui.Component implements  eui.UIComponent {
	public Group_mbtn:eui.Group; //可通过id找到子组件
	public constructor() {
		super();
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		// 让btn_group可以点击
		this.Group_mbtn.touchEnabled = true;

		// 事件委托，点击按钮时触发toggleBtn
		this.Group_mbtn.addEventListener(egret.TouchEvent.TOUCH_TAP,(e)=>{
			let theBtn = e.target;
			if(theBtn.selected && theBtn.selected !=undefined){
				this.toggleBtn(theBtn);
			}
		},this)
	}
	/**
	 * 切换按钮组状态
	 * @param btn:参数为toggleButton时切换按钮，参数为0时都不选中
	 */
	public toggleBtn(btn:eui.ToggleButton | number){
		for(let i = 0,len = this.Group_mbtn.numChildren;i<len;i++){
			let theBtn=<eui.ToggleButton> this.Group_mbtn.getChildAt(i);
			theBtn.selected = false;
		}
		if(btn===0){
			return
		}
		btn = <eui.ToggleButton>btn;
		btn.selected = true;
		let index = this.Group_mbtn.getChildIndex(<eui.ToggleButton>btn);
		egret.log(this.numChildren)
		switch(index){
			case 0:
			// 切换到玩家场景
			SceneManager.toPlayerScene();
			// 提高按钮层级
			this.setChildIndex(this.Group_mbtn,this.numChildren)
			break;
			case 1:
			// 切换到玩家场景
			SceneManager.toHeroScene();
			// 提高按钮层级
			this.setChildIndex(this.Group_mbtn,this.numChildren)
			break;
			default:
			break;
		}


	}

	
}